//============================================================================
// Name        : ShowUnregisteredCoursesVersion2.cpp
// Author      : Sartios
// Version     :
// Copyright   : (C) Savramis Sartios
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include "Controllers/ContentControllers/CourseWithTeachersListControllers/Creator/CourseWithTeachersCreator.h"
#include "Controllers/ContentControllers/TeacherControllers/TeacherCreator/TeacherCreator.h"
#include "Controllers/ContentControllers/CourseController/CourseCreator.h"
#include "Controllers/ContentControllers/TeacherListControllers/Creator/TeacherListCreator.h"
#include "Domain/UnregisteredCourses/Lists/UnregisteredCourses.h"

using namespace std;

int main() {
	ICourse				*course ;
	ITeacher			*teacher;
	ITeacherList		*teacherList;
	ICourseWithTeacher 	*courseWithTeachers;

	ICourseCreator				*courseCreator = new CourseCreator;
	ITeacherCreator				*teacherCreator = new TeacherCreator;
	ICourseWithTeachersCreator 	*courseWithTeachersCreator = new CourseWithTeachersCreator;
	ITeacherListCreator			*teacherListCreator = new TeacherListCreator;

	string	*courseCode=new string;
	string	*courseTitle=new string;
	string	*teacherCode = new  string;
	string	*teacherName=new string;
	string	*teacherLastName=new string;

	cout<<"\nCourse code: ";
	cin>>*courseCode;
	cout<<"\nCourse Title: ";
	cin>>*courseTitle;
	cout<<"\nTeacher code: ";
	cin>>*teacherCode;
	cout<<"\nTeacher name: ";
	cin>>*teacherName;
	cout<<"\nTeacher last name: ";
	cin>>*teacherLastName;


	course = courseCreator->getCourse(courseCode,courseTitle);

	teacher = teacherCreator->getTeacher(teacherCode,teacherName,teacherLastName);

	teacherList = teacherListCreator->getEmptyTeacherList();

	for(int i=0;i<2;i++){
		teacherListCreator->addTeacher(teacherList,teacher);
	}

	courseWithTeachers = courseWithTeachersCreator->getCourseWithTeacherList(course,teacherList);

	//courseWithTeacher->addTeacher(teacher);


	ITeacherIterator *it;

	it=courseWithTeachers->getTeacherIterator();

	//cout<<*(courseWithTeacher->getCourse()->getCode())<<endl;
	for(it->first();!it->isDone();it->next()){
		ITeacher *tmp = it->getTeacher();
		cout<<*tmp->getCode()<<endl;

		cout<<*(courseWithTeachers->getCourse()->getTitle());
		cout<<"\t"<<*tmp->getLastName()<<"\t"<<*tmp->getName()<<endl;
	}

	IUnregisteredCourses	*unCourses=new UnregisteredCourses;

	unCourses->add(courseWithTeachers);
	unCourses->add(courseWithTeachers);

	IUnregisteredCoursesSerialIterator *serial = unCourses->getSerialIterator();
	ICourseWithTeacher 	*tmpCourses;
	ITeacherIterator	*tmpTeachers;

	for(serial->first();!serial->isDone();serial->next()){
		cout<<"\n\n";
		tmpCourses=serial->getCurrent();
		tmpTeachers = tmpCourses->getTeacherIterator();
		for(tmpTeachers->first();!tmpTeachers->isDone();tmpTeachers->next()){

			ITeacher *tmp = tmpTeachers->getTeacher();
		//	cout<<*tmp->getCode()<<endl;

			cout<<*(courseWithTeachers->getCourse()->getTitle());
			cout<<"\t"<<*tmp->getLastName()<<"\t"<<*tmp->getName()<<endl;
		}
	}

	delete tmpCourses;
	delete tmpTeachers;
	delete serial;
	delete unCourses;
	delete course;
	delete courseWithTeachers;
	delete teacher;
	delete courseCode;
	delete teacherLastName;
	delete teacherName;
	delete courseTitle;
	delete teacherList;
}
